<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="bootstrap/assets/ico/favicon.png">
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

    <title>Admin Panel</title>

    <!-- Bootstrap core CSS -->
    <link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Custom styles for this template -->
    <link href="css/following.css" rel="stylesheet">
    
    <script>
	    function deleteStory(storyId){
	    	
	    	var url = "DeleteStory";
	    	
    		$.ajax({
    			type: "GET",
    			url: url,
    			data: {
    				story_id: storyId
    			},
    			success: function(data){
    				$('#stories').click();
    			}
    		});
		}
		
		function banUser(username){
			
			var url = "BanUser";
	    	
    		$.ajax({
    			type: "GET",
    			url: url,
    			data: {
    				banUsername: username
    			},
    			success: function(data){
    				$('#users').click();
    			}
    		});
		}
		
		function deleteUser(username){

			var url = "DeleteUser";
	    	
    		$.ajax({
    			type: "GET",
    			url: url,
    			data: {
    				deleteUsername: username
    			},
    			success: function(data){
    				$('#users').click();
    			}
    		});
		}
    </script>
    
       <script type="text/javascript">
        $(document)
            .ready(
                function () {
                	$("#stories").click(function(){
                		var url = "GetReportedStories";
                		$("#following-page-container").html('');
                		$.ajax({
                			type: "GET",
                			url: url,
                			dataType: "json",
                			success: function(data){
                				$.map(data.reportedStories, function(item){
                					$('#following-page-container').append(
                							'<div><h3 style="margin-left:5%"><a href="ReadStory?story_id=' +
                                            item.s_id + '">' + item.title +
                                            '</a></h3>'+
                                            '<div><button type="button" style="float:right;" class="btn btn-primary btn-default" onclick="deleteStory('+(item.s_id)+')">Delete Story</button>'+
                                            '</div></div><hr style="margin-top:5%">');
                				});
                			}
                		});
                		
                	});
                	
                	$("#users").click(function(){
                		var url = "GetAllUsers";
                		$("#following-page-container").html('');
                		$.ajax({
                			type: "GET",
                			url: url,
                			data: {
                                query: ""
                            },
                			dataType: "json",
                			success: function(data){
                				var users = data.results;
                				for (var i = 0; i < users.length; i++) {
                					$('#following-page-container').append(
                							'<div><h3 style="margin-left:5%"><a href="GetProfile?targetname=' +
                                            users[i] + '">' + users[i] +
                                            '</a></h3>'+
                                            '<div><button type="button" id="adminbutton" style="float:right;" class="btn btn-danger btn-default" onclick="banUser(\''+users[i]+'\')">Ban User</button></div>'+
                                            '<div><button type="button" id="adminbutton" style="float:right;" class="btn btn-danger btn-default"onclick="deleteUser(\''+users[i]+'\')">Delete User</button></div>'+
                                            '</div></div><hr style="margin-top:5%">');
                				}
                			}
                		});
                    	
                	});
                });
        </script>
    
  </head>
   
  <body background="img/back_nologo.png">
    <div class="navbar navbar-fixed-top navbar-inverse" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <img src="img/logo_writing.png" id="top_logo">
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav" id="profile_buttons">
            <li><a href="Logout">Logout</a></li>
          </ul>
        </div><!-- /.nav-collapse -->
      </div><!-- /.container -->
    </div><!-- /.navbar -->
    
    <div class="container">    
      <div class="well sidebar-nav" id="following-title">
      <center>
        <button class="btn btn-primary btn-default" id="stories">Get Reported Stories</button> 
        	<button class="btn btn-primary btn-default" id="users">Get Users</button>
        	</center>
      </div>         
      <div class="well sidebar-nav" id="following-page-container">
        <div id="user" class="active">
         <%--  <div id="gotoprofile-button"><button type="button" onclick='window.location="GetProfile?targetname=<%out.print(followed.get(i).getUsername());%>"'
          	class="btn btn-primary btn-default">Go to profile</button></div>
           <div id="unfollow-button"><button type="button"  onclick='window.location="Unfollow?f_username=<%out.print(followed.get(i).getUsername()); %>"'
           class="btn btn-danger btn-default">Unfollow</button></div>
        </div> --%>
      </div>
    </div>    
    </div>
  </body>
</html>